<?php
/**
 * $Id: ajax.php 710 2010-09-06 08:11:52Z shrey $
 * 
 * This file can not be redistributed to anyone without the permission of Giga Promoters
 * Copyright 2005 - 2008, Giga Promoters
 * 						  608 Aggarwal Cyber Plaza
 *						  Netaji Subhash Place, Delhi - 110034
 *						  www.gigapromoters.com
 * 
 *
 * This is parent of parent class of a controller and should not be edited ever without permission.
 * @version 			$Rev: 710 $
 * @lastModifiedBy		$LastChangedBy: shrey $
 * @lastChanged			$Date: 2010-09-06 13:41:52 +0530 (Mon, 06 Sep 2010) $
 * @copyright 			Giga Promoters (www.gigapromoters.com)
 * 
 */

/**
 * Future AJAX Helper of our CMS
 *
 */
class AjaxHelper extends AppHelper 
{
	var $helpers = array('Html', 'Javascript');
	
	/**
	 * Adds scripts for ajax divs
	 * @return unknown_type
	 */
	function _addAjaxification()
	{
		$script = $this->Javascript->link('/cms/js/jquery.ajaxify.js',false);
		$script = $this->Javascript->link('/effects/js/jquery.form.js',false);
		$script = $this->Javascript->link('/cms/js/giga_ajax_lib.js',false);
	}
	
	function div($url, $options = array(), $divOptions = array())
	{
		$this->_addAjaxification();
		
		$defaultOptions = array(
			'preload' => false,
			'recursive' => false
		);
		$options = am($defaultOptions, $options);
		extract($options);
		
		$jsonOptions = json_encode($options);

		if(!isset($divOptions['id']))
		{
			$divOptions['id'] = 'ajaxDiv_'.mt_rand();
		}
		$this->Javascript->startup("GigaAjax.init('".$divOptions['id']."', '$url', $jsonOptions);");
		
		$content = "";
		if($preload)
		{
			$content = $this->requestAction($url, array('return', 'layout'=>'ajax','bare'=>0, 'autoRender'=>true)); // same as RequestHandler::beforeRedirect()
		}
		return $this->Html->tag('div', $content, $divOptions);
	}

}

?>